﻿using System;
using System.Drawing;
using System.Web.Script.Serialization;
using System.Xml.Serialization;

namespace dmp_ui_demo
{
    [Serializable]
    public class HighlightKey
    {
        /// <summary>
        /// 关键字
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 背景色
        /// </summary>
        public Color BackColor { get; set; }

        /// <summary>
        /// 前景色
        /// </summary>
        [XmlIgnore]
        [ScriptIgnore]
        public Color ForeColor
        {
            get
            {
                //转灰度，为了在黑白打印的时候能看清楚
                int ret = (int)(BackColor.R * 0.299 + BackColor.G * 0.587 + BackColor.B * 0.114);
                Color forceColor = Color.FromArgb(ret, ret, ret);
                //根据灰度色的亮度用黑色或者白色做对比
                var brightness = forceColor.GetBrightness();

                if (brightness < 0.5)
                {
                    forceColor = Color.White;
                }
                else
                {
                    forceColor = Color.Black;
                }
                return forceColor;
            }
        }

        /// <summary>
        /// 修正建议
        /// </summary>
        public string Suggest { get; set; }
    }
}
